﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwArtiklKategorijaProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwArtiklKategorijaProviderBaseCore : EntityViewProviderBase<VwArtiklKategorija>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwArtiklKategorija&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwArtiklKategorija&gt;"/></returns>
		protected static VList&lt;VwArtiklKategorija&gt; Fill(DataSet dataSet, VList<VwArtiklKategorija> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwArtiklKategorija>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwArtiklKategorija&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwArtiklKategorija>"/></returns>
		protected static VList&lt;VwArtiklKategorija&gt; Fill(DataTable dataTable, VList<VwArtiklKategorija> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwArtiklKategorija c = new VwArtiklKategorija();
					c.ID = (Convert.IsDBNull(row["ID"]))?(int)0:(System.Int32)row["ID"];
					c.Naziv = (Convert.IsDBNull(row["Naziv"]))?string.Empty:(System.String)row["Naziv"];
					c.Hierarchy = (Convert.IsDBNull(row["Hierarchy"]))?string.Empty:(System.String)row["Hierarchy"];
					c.Put = (Convert.IsDBNull(row["Put"]))?string.Empty:(System.String)row["Put"];
					c.IDRoditelj = (Convert.IsDBNull(row["IDRoditelj"]))?(int)0:(System.Int32?)row["IDRoditelj"];
					c.Abstraktna = (Convert.IsDBNull(row["Abstraktna"]))?false:(System.Boolean)row["Abstraktna"];
					c.Lvl = (Convert.IsDBNull(row["Lvl"]))?(int)0:(System.Int32?)row["Lvl"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwArtiklKategorija&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwArtiklKategorija&gt;"/></returns>
		protected VList<VwArtiklKategorija> Fill(IDataReader reader, VList<VwArtiklKategorija> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwArtiklKategorija entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwArtiklKategorija>("VwArtiklKategorija",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwArtiklKategorija();
					}
					entity.ID = (System.Int32)reader["ID"];
					//entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
					entity.Naziv = (System.String)reader["Naziv"];
					//entity.Naziv = (Convert.IsDBNull(reader["Naziv"]))?string.Empty:(System.String)reader["Naziv"];
					entity.Hierarchy = (System.String)reader["Hierarchy"];
					//entity.Hierarchy = (Convert.IsDBNull(reader["Hierarchy"]))?string.Empty:(System.String)reader["Hierarchy"];
					entity.Put = reader.IsDBNull(reader.GetOrdinal("Put")) ? null : (System.String)reader["Put"];
					//entity.Put = (Convert.IsDBNull(reader["Put"]))?string.Empty:(System.String)reader["Put"];
					entity.IDRoditelj = reader.IsDBNull(reader.GetOrdinal("IDRoditelj")) ? null : (System.Int32?)reader["IDRoditelj"];
					//entity.IDRoditelj = (Convert.IsDBNull(reader["IDRoditelj"]))?(int)0:(System.Int32?)reader["IDRoditelj"];
					entity.Abstraktna = (System.Boolean)reader["Abstraktna"];
					//entity.Abstraktna = (Convert.IsDBNull(reader["Abstraktna"]))?false:(System.Boolean)reader["Abstraktna"];
					entity.Lvl = reader.IsDBNull(reader.GetOrdinal("Lvl")) ? null : (System.Int32?)reader["Lvl"];
					//entity.Lvl = (Convert.IsDBNull(reader["Lvl"]))?(int)0:(System.Int32?)reader["Lvl"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwArtiklKategorija"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwArtiklKategorija"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwArtiklKategorija entity)
		{
			reader.Read();
			entity.ID = (System.Int32)reader["ID"];
			//entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
			entity.Naziv = (System.String)reader["Naziv"];
			//entity.Naziv = (Convert.IsDBNull(reader["Naziv"]))?string.Empty:(System.String)reader["Naziv"];
			entity.Hierarchy = (System.String)reader["Hierarchy"];
			//entity.Hierarchy = (Convert.IsDBNull(reader["Hierarchy"]))?string.Empty:(System.String)reader["Hierarchy"];
			entity.Put = reader.IsDBNull(reader.GetOrdinal("Put")) ? null : (System.String)reader["Put"];
			//entity.Put = (Convert.IsDBNull(reader["Put"]))?string.Empty:(System.String)reader["Put"];
			entity.IDRoditelj = reader.IsDBNull(reader.GetOrdinal("IDRoditelj")) ? null : (System.Int32?)reader["IDRoditelj"];
			//entity.IDRoditelj = (Convert.IsDBNull(reader["IDRoditelj"]))?(int)0:(System.Int32?)reader["IDRoditelj"];
			entity.Abstraktna = (System.Boolean)reader["Abstraktna"];
			//entity.Abstraktna = (Convert.IsDBNull(reader["Abstraktna"]))?false:(System.Boolean)reader["Abstraktna"];
			entity.Lvl = reader.IsDBNull(reader.GetOrdinal("Lvl")) ? null : (System.Int32?)reader["Lvl"];
			//entity.Lvl = (Convert.IsDBNull(reader["Lvl"]))?(int)0:(System.Int32?)reader["Lvl"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwArtiklKategorija"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwArtiklKategorija"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwArtiklKategorija entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.ID = (Convert.IsDBNull(dataRow["ID"]))?(int)0:(System.Int32)dataRow["ID"];
			entity.Naziv = (Convert.IsDBNull(dataRow["Naziv"]))?string.Empty:(System.String)dataRow["Naziv"];
			entity.Hierarchy = (Convert.IsDBNull(dataRow["Hierarchy"]))?string.Empty:(System.String)dataRow["Hierarchy"];
			entity.Put = (Convert.IsDBNull(dataRow["Put"]))?string.Empty:(System.String)dataRow["Put"];
			entity.IDRoditelj = (Convert.IsDBNull(dataRow["IDRoditelj"]))?(int)0:(System.Int32?)dataRow["IDRoditelj"];
			entity.Abstraktna = (Convert.IsDBNull(dataRow["Abstraktna"]))?false:(System.Boolean)dataRow["Abstraktna"];
			entity.Lvl = (Convert.IsDBNull(dataRow["Lvl"]))?(int)0:(System.Int32?)dataRow["Lvl"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwArtiklKategorijaFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwArtiklKategorija"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwArtiklKategorijaFilterBuilder : SqlFilterBuilder<VwArtiklKategorijaColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwArtiklKategorijaFilterBuilder class.
		/// </summary>
		public VwArtiklKategorijaFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwArtiklKategorijaFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwArtiklKategorijaFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwArtiklKategorijaFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwArtiklKategorijaFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwArtiklKategorijaFilterBuilder

	#region VwArtiklKategorijaParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwArtiklKategorija"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwArtiklKategorijaParameterBuilder : ParameterizedSqlFilterBuilder<VwArtiklKategorijaColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwArtiklKategorijaParameterBuilder class.
		/// </summary>
		public VwArtiklKategorijaParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwArtiklKategorijaParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwArtiklKategorijaParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwArtiklKategorijaParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwArtiklKategorijaParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwArtiklKategorijaParameterBuilder
} // end namespace
